package com.hyb.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hyb.entity.Contacts;
import com.hyb.mapper.ContactsMapper;
import com.hyb.page.PageReq;
import com.hyb.service.ContactsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  客户联系人Service接口实现类
 * </p>
 *
 * @author hyb
 * @since 2021-12-29
 */
@Service
public class ContactsServiceImpl extends ServiceImpl<ContactsMapper, Contacts> implements ContactsService {

    @Autowired
    private ContactsMapper contactsMapper;

    @Override
    public void createContacts(Contacts contacts) {
        contactsMapper.insert(contacts);
    }

    @Override
    public PageReq loadContactsByCustomerId(Integer limit, Integer current, Integer customerId) {
        Page<Contacts> page = new Page<>(current,limit);
        IPage<Contacts> contactsIPage = contactsMapper.selectContactByCustomerId(page, customerId);
        PageReq pageReq = new PageReq();
        pageReq.setTotal(contactsIPage.getTotal());
        pageReq.setMyData(contactsIPage.getRecords());
        return pageReq;
    }

    @Override
    public Contacts getContactByContactId(Integer contactId) {
        return contactsMapper.selectById(contactId);
    }

    @Override
    public void updateContact(Contacts contacts) {
        contactsMapper.updateById(contacts);
    }

    @Override
    public void deleteContactByContactId(Integer contactId) {
        contactsMapper.deleteById(contactId);
    }
}
